package gui;


import java.awt.*;
import java.awt.event.*;



import javax.swing.*;






import Lexicon.Lexicon;
import Lexicon.MyNode;


public class SearchPanel extends JPanel
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JFormattedTextField arWord;
	private JButton searchButton;
	private JFormattedTextField engWord;
	public SearchPanel()
	{
		//construct components
		arWord = new JFormattedTextField ();
		arWord.setFont(new Font("Lucida Sans", Font.BOLD, 12));
		
		searchButton = new JButton ("<HTML><FONT COLOR=blue size =5 >"+ArMT.labels.getString("searchButton")+"</FONT></HTML>");
		searchButton.addActionListener(new ActionListener(){
		      public void actionPerformed(ActionEvent e){		    
				MyNode n ;
				 if((n = Lexicon.searchTree.find(arWord.getText())) != null)
				      engWord.setText(n.getEnglishWord());
				 else if((n = Lexicon.wordTree.find(arWord.getText()))!= null)
					 engWord.setText(n.getEnglishWord());
				 else if((n = Lexicon.currentTree.find(arWord.getText()))!= null)
					 engWord.setText(n.getEnglishWord());
				 else if ((n = AdditionPanel.newDic.find(arWord.getText()))!= null)
					 engWord.setText(n.getEnglishWord());
				 else JOptionPane.showMessageDialog(null,ArMT.labels.getString("unsupportedInfMess"),ArMT.labels.getString("unsupportedWord"),JOptionPane.INFORMATION_MESSAGE);
		         
		      }
		}
		      );
		ArMT.applyComponentOrientation(this, ArMT.co);
		engWord = new JFormattedTextField ();

		//adjust size and set layout
		setPreferredSize (new Dimension (587, 90));
		GridLayout layout = new GridLayout(1, 3, 30, 4);
		setLayout (layout);
		setBorder(BorderFactory.createCompoundBorder(
				BorderFactory.createTitledBorder(ArMT.labels.getString("searchDicBorder")), BorderFactory.createEmptyBorder(15,15,15,15)
				)
				);
		//add components
		add (arWord);
		add (searchButton);
		add (engWord);
	}
	/* throws UnsupportedLookAndFeelException
	{
		JFrame frame = new JFrame ("JPanel Preview");
		UIManager.setLookAndFeel(new SubstanceLookAndFeel());
		frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().add (new SearchPanel());
		frame.pack();
		frame.setVisible (true);
	}*/
	public  JFormattedTextField getEngWord() {
		return engWord;
	}
	public JFormattedTextField getArWord() {
		return arWord;
	}
}

